function [ organized_data ] = organize(data)
	load_settings;
	disp('Organize: Starting organization');
	organized_data = data(1);

	% sort data by cam_id then by time
	fields = fieldnames(data);
	data_cell = struct2cell(data);
	sz = size(data_cell);
	data_cell = reshape(data_cell, sz(1), []);
	data_cell = data_cell';
	data_sortable = sortrows(data_cell, [1 2 3] ); % cam_id, day, hour
	data_cell = reshape(data_sortable', sz);
	data_sorted = cell2struct(data_cell, fields, 1);

	pci = 0;
	cam_index = 0;
	img_index = 1;
	images = {};
	cameras = [];
	for ix = 1:length(data_sorted)
	
		camfind = find(cameras == data_sorted(ix).cam_id);
		if camfind % already seen camera
			imfind = find(strcmp(images{camfind}, data_sorted(ix).filename));
			if imfind % already seen image
				% add rects and hogs to old entry
				if ~isequal(organized_data(camfind,imfind).ppl_rects, data_sorted(ix).ppl_rects) % diff ppl_rects
					organized_data(camfind,imfind).ppl_rects = [organized_data(camfind,imfind).ppl_rects; data_sorted(ix).ppl_rects];
					organized_data(camfind,imfind).ppl_hogs  = [organized_data(camfind,imfind).ppl_hogs;  data_sorted(ix).ppl_hogs];
				end
				if ~isequal(organized_data(camfind,imfind).bg_rects, data_sorted(ix).bg_rects) % diff bg_rects
					organized_data(camfind,imfind).bg_rects = [organized_data(camfind,imfind).bg_rects; data_sorted(ix).bg_rects];
					organized_data(camfind,imfind).bg_hogs  = [organized_data(camfind,imfind).bg_hogs;  data_sorted(ix).bg_hogs];
				end
			else % new image
				img_index = img_index+1;
				images{camfind}{img_index} = data_sorted(ix).filename;
				organized_data(camfind, img_index) = data_sorted(ix);
			end
		else % new camera
			cam_index = cam_index+1;
			img_index = 1;
			cameras(cam_index) = data_sorted(ix).cam_id;
			images{cam_index}  = {data_sorted(ix).filename};
			organized_data(cam_index, img_index) = data_sorted(ix);
		
		end
		
	   % if pci == data_sorted(ix).cam_id 
	   %      img_index = img_index+1;
	   % else
	   %     cam_index = cam_index+1;
	   %     img_index = 1;
	   % end
	   % organized_data(cam_index, img_index) = data_sorted(ix);
	   % pci = data_sorted(ix).cam_id;
	end
	
	disp('Organize: Done organization');
end
